package net.awpspace.mp3player.screen;

import java.io.IOException;
import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.List;

import net.awpspace.mp3player.Application;

public class PlaylistsScreen extends List implements ItemStateListener,
		CommandListener {

	private Vector list;
	private Image img_list_playing;
	private Image img_my_list;

	private Command select;

	public PlaylistsScreen() {
		super("Playlists", List.IMPLICIT);
		init();

	}

	private void init() {
		list = new Vector();
		try {
			img_list_playing = Image.createImage("/list_playing.png");
			img_my_list = Image.createImage("/my_list.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//
		this.append("Now playing", img_list_playing);
		this.append("My playlists", img_my_list);

		// init command
		select = new Command("Select", Command.ITEM, 0);
		// add = new Command("add", Image.createImage("/add_icon.png"));
		// setDefaultCommand(add);
		// addCommand(add);
		this.setCommandListener(this);
		this.setSelectCommand(select);

		
	}

	public void commandAction(Command cmd, Displayable d) {
		// TODO Auto-generated method stub
		if (cmd == select) {
			int index = this.getSelectedIndex();
			System.out.println("index: "+index);
			if (index == 0) {
				ListMusic lm = new ListMusic("All tracks", List.IMPLICIT);
				lm.createListMusic(PlayScreen.list);
				Application.getDisplay().setCurrent(lm);
			}else if(index == 1){
				Application.getDisplay().setCurrent(MyPlaylistsScreen.getInstance());
			}
		} else {
		}
	}

	public void itemStateChanged(Item selected) {
		// TODO Auto-generated method stub
	}

}
